<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 5.4.2">
  <link rel="apple-touch-icon" sizes="180x180" href="/images/avatar.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/avatar.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/avatar.png">
  <link rel="mask-icon" href="/images/avatar.png" color="#222">

<link rel="stylesheet" href="/css/main.css">


<link rel="stylesheet" href="/lib/font-awesome/css/all.min.css">
  <link rel="stylesheet" href="//cdn.jsdelivr.net/gh/fancyapps/fancybox@3/dist/jquery.fancybox.min.css">

<script id="hexo-configurations">
    var NexT = window.NexT || {};
    var CONFIG = {"hostname":"notes.maxwi.com","root":"/","scheme":"Mist","version":"7.8.0","exturl":false,"sidebar":{"position":"right","display":"post","padding":18,"offset":12,"onmobile":false},"copycode":{"enable":false,"show_result":false,"style":null},"back2top":{"enable":true,"sidebar":false,"scrollpercent":false},"bookmark":{"enable":true,"color":"#222","save":"auto"},"fancybox":true,"mediumzoom":false,"lazyload":true,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":true,"nav":null},"algolia":{"hits":{"per_page":10},"labels":{"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}},"localsearch":{"enable":true,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false},"motion":{"enable":false,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},"path":"search.xml"};
  </script>

  <meta name="description" content="系统为ubuntu 16.04.1 x64，具体参数如下： 1234DISTRIB_ID&#x3D;UbuntuDISTRIB_RELEASE&#x3D;16.04DISTRIB_CODENAME&#x3D;xenialDISTRIB_DESCRIPTION&#x3D;&quot;Ubuntu 16.04.1 LTS&quot; 系统为Ubuntu 64位服务器版的最小化系统安装Nvidia官网最新版本的CUDA 8(2016.12.1">
<meta property="og:type" content="article">
<meta property="og:title" content="Ubuntu 16.04下CUDA8环境配置的2种方法">
<meta property="og:url" content="http://notes.maxwi.com/2017/02/26/ubuntu-cuda8-env-set/index.html">
<meta property="og:site_name" content="blueyi&#39;s notes">
<meta property="og:description" content="系统为ubuntu 16.04.1 x64，具体参数如下： 1234DISTRIB_ID&#x3D;UbuntuDISTRIB_RELEASE&#x3D;16.04DISTRIB_CODENAME&#x3D;xenialDISTRIB_DESCRIPTION&#x3D;&quot;Ubuntu 16.04.1 LTS&quot; 系统为Ubuntu 64位服务器版的最小化系统安装Nvidia官网最新版本的CUDA 8(2016.12.1">
<meta property="og:locale" content="en_US">
<meta property="article:published_time" content="2017-02-26T06:36:51.000Z">
<meta property="article:modified_time" content="2017-02-26T06:36:51.000Z">
<meta property="article:author" content="blueyi">
<meta property="article:tag" content="CUDA">
<meta property="article:tag" content="Linux">
<meta property="article:tag" content="Ubuntu">
<meta name="twitter:card" content="summary">

<link rel="canonical" href="http://notes.maxwi.com/2017/02/26/ubuntu-cuda8-env-set/">


<script id="page-configurations">
  // https://hexo.io/docs/variables.html
  CONFIG.page = {
    sidebar: "",
    isHome : false,
    isPost : true,
    lang   : 'en'
  };
</script>

  <title>Ubuntu 16.04下CUDA8环境配置的2种方法 | blueyi's notes</title>
  






  <noscript>
  <style>
  .use-motion .brand,
  .use-motion .menu-item,
  .sidebar-inner,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-header { opacity: initial; }

  .use-motion .site-title,
  .use-motion .site-subtitle {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line-before i { left: initial; }
  .use-motion .logo-line-after i { right: initial; }
  </style>
</noscript>

<link rel="alternate" href="/atom.xml" title="blueyi's notes" type="application/atom+xml">
<link rel="alternate" href="/rss2.xml" title="blueyi's notes" type="application/rss+xml">
</head>

<body itemscope itemtype="http://schema.org/WebPage">
  <div class="container">
    <div class="headband"></div>

    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="Toggle navigation bar">
      <span class="toggle-line toggle-line-first"></span>
      <span class="toggle-line toggle-line-middle"></span>
      <span class="toggle-line toggle-line-last"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/" class="brand" rel="start">
      <span class="logo-line-before"><i></i></span>
      <h1 class="site-title">blueyi's notes</h1>
      <span class="logo-line-after"><i></i></span>
    </a>
      <p class="site-subtitle" itemprop="description">Follow Excellence,Success will chase you!</p>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger">
        <i class="fa fa-search fa-fw fa-lg"></i>
    </div>
  </div>
</div>




<nav class="site-nav">
  <ul id="menu" class="main-menu menu">
        <li class="menu-item menu-item-home">

    <a href="/" rel="section"><i class="fa fa-home fa-fw"></i>Home</a>

  </li>
        <li class="menu-item menu-item-categories">

    <a href="/categories/" rel="section"><i class="fa fa-th fa-fw"></i>Categories</a>

  </li>
        <li class="menu-item menu-item-archives">

    <a href="/archives/" rel="section"><i class="fa fa-archive fa-fw"></i>Archives</a>

  </li>
        <li class="menu-item menu-item-tags">

    <a href="/tags/" rel="section"><i class="fa fa-tags fa-fw"></i>Tags</a>

  </li>
        <li class="menu-item menu-item-about">

    <a href="/about/" rel="section"><i class="fa fa-user fa-fw"></i>About</a>

  </li>
      <li class="menu-item menu-item-search">
        <a role="button" class="popup-trigger"><i class="fa fa-search fa-fw"></i>Search
        </a>
      </li>
  </ul>
</nav>



  <div class="search-pop-overlay">
    <div class="popup search-popup">
        <div class="search-header">
  <span class="search-icon">
    <i class="fa fa-search"></i>
  </span>
  <div class="search-input-container">
    <input autocomplete="off" autocapitalize="off"
           placeholder="Searching..." spellcheck="false"
           type="search" class="search-input">
  </div>
  <span class="popup-btn-close">
    <i class="fa fa-times-circle"></i>
  </span>
</div>
<div id="search-result">
  <div id="no-result">
    <i class="fa fa-spinner fa-pulse fa-5x fa-fw"></i>
  </div>
</div>

    </div>
  </div>

</div>
    </header>

    
  <div class="back-to-top">
    <i class="fa fa-arrow-up"></i>
    <span>0%</span>
  </div>
  <div class="reading-progress-bar"></div>
  <a role="button" class="book-mark-link book-mark-link-fixed"></a>


    <main class="main">
      <div class="main-inner">
        <div class="content-wrap">
          

          <div class="content post posts-expand">
            

    
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="en">
    <link itemprop="mainEntityOfPage" href="http://notes.maxwi.com/2017/02/26/ubuntu-cuda8-env-set/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/default_avatar.jpg">
      <meta itemprop="name" content="blueyi">
      <meta itemprop="description" content="心怀善意，虛怀若谷！">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="blueyi's notes">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          Ubuntu 16.04下CUDA8环境配置的2种方法
        </h1>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-calendar"></i>
              </span>
              <span class="post-meta-item-text">Posted on</span>

              <time title="Created: 2017-02-26 14:36:51" itemprop="dateCreated datePublished" datetime="2017-02-26T14:36:51+08:00">2017-02-26</time>
            </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-folder"></i>
              </span>
              <span class="post-meta-item-text">In</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/CUDA/" itemprop="url" rel="index"><span itemprop="name">CUDA</span></a>
                </span>
            </span>

          <br>
            <span class="post-meta-item" title="Symbols count in article">
              <span class="post-meta-item-icon">
                <i class="far fa-file-word"></i>
              </span>
                <span class="post-meta-item-text">Symbols count in article: </span>
              <span>7.1k</span>
            </span>
            <span class="post-meta-item" title="Reading time">
              <span class="post-meta-item-icon">
                <i class="far fa-clock"></i>
              </span>
                <span class="post-meta-item-text">Reading time &asymp;</span>
              <span>6 mins.</span>
            </span>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
        <p>系统为ubuntu 16.04.1 x64，具体参数如下：</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">DISTRIB_ID=Ubuntu</span><br><span class="line">DISTRIB_RELEASE=16.04</span><br><span class="line">DISTRIB_CODENAME=xenial</span><br><span class="line">DISTRIB_DESCRIPTION=&quot;Ubuntu 16.04.1 LTS&quot;</span><br></pre></td></tr></table></figure>
<p>系统为Ubuntu 64位服务器版的最小化系统<br>安装Nvidia官网最新版本的CUDA 8(2016.12.19)<br>下面分别使用Nvidia官方手册中使用deb源的方式安装，和根据Nvidia提供的二进制包配合双显卡技术的方式安装。前者更新更方便，后者针对双显卡最方便。服务器系统推荐使用第一种方式安装，笔记本建议使用第二种方式，因为可以实现双显卡，集显更省电。<br>如果只是为了玩游戏需要配置Ubuntu下的Nvidia和intel双显卡，也可以直接跳到双显卡切换的配置部分</p>
<span id="more"></span>

<h1 id="根据nvidia官方手册安装"><a href="#根据nvidia官方手册安装" class="headerlink" title="根据nvidia官方手册安装"></a>根据nvidia官方手册安装</h1><p>该安装方法由于是在服务器系统下测试，并没有桌面环境，所以不保证安装配置完成之后依然能进入桌面环境。</p>
<h2 id="安装准备"><a href="#安装准备" class="headerlink" title="安装准备"></a>安装准备</h2><h3 id="验证NVIDIA显卡"><a href="#验证NVIDIA显卡" class="headerlink" title="验证NVIDIA显卡"></a>验证NVIDIA显卡</h3><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_">$ </span><span class="language-bash">lspci | grep -i nvidia</span></span><br></pre></td></tr></table></figure>
<p>看看是否有nvidia的显卡</p>
<h3 id="查看linux系统信息"><a href="#查看linux系统信息" class="headerlink" title="查看linux系统信息"></a>查看linux系统信息</h3><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_">$ </span><span class="language-bash"><span class="built_in">uname</span> -m &amp;&amp; <span class="built_in">cat</span> /etc/*release</span></span><br></pre></td></tr></table></figure>
<p>确保你的系统在nvidia官方的cuda支持列表中</p>
<h3 id="安装gcc及g"><a href="#安装gcc及g" class="headerlink" title="安装gcc及g++"></a>安装gcc及g++</h3><p>就是安装C++开发环境，因为CUDA是基于C/C++开发的，当然现在也支持很多其他语言</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_">$ </span><span class="language-bash">sudo apt-get install gcc g++</span></span><br></pre></td></tr></table></figure>

<h3 id="安装linux-kernel-header及开发包"><a href="#安装linux-kernel-header及开发包" class="headerlink" title="安装linux kernel header及开发包"></a>安装linux kernel header及开发包</h3><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_">$ </span><span class="language-bash">sudo apt-get install linux-headers-$(<span class="built_in">uname</span> -r)</span></span><br></pre></td></tr></table></figure>
<p>为了避免出现头文件相关的问题，推荐安装上build-essential：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_">$ </span><span class="language-bash">sudo apt-get install build-essential</span></span><br></pre></td></tr></table></figure>

<h2 id="下载并安装CUDA"><a href="#下载并安装CUDA" class="headerlink" title="下载并安装CUDA"></a>下载并安装CUDA</h2><p>下载CUDA：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_">$ </span><span class="language-bash">wget --no-check-certificate https://developer.nvidia.com/compute/cuda/8.0/prod/local_installers/cuda-repo-ubuntu1604-8-0-local_8.0.44-1_amd64-deb</span></span><br></pre></td></tr></table></figure>
<p>通过以下命令安装cuda源：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_">$ </span><span class="language-bash">sudo dpkg -i cuda-repo-ubuntu1604-8-0-local_8.0.44-1_amd64-deb</span></span><br></pre></td></tr></table></figure>
<p>如果是下载的local版本，实际上会在本地增加一个local源，指定为cuda的解压路径，如果是网络源，实际上会添加以下源：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">deb http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1604/x86_64 /</span><br></pre></td></tr></table></figure>

<p>更新包缓存：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_">$ </span><span class="language-bash">sudo apt-get update</span></span><br></pre></td></tr></table></figure>

<p>安装CUDA：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_">$ </span><span class="language-bash">sudo apt-get install cuda</span></span><br></pre></td></tr></table></figure>

<h2 id="设置环境变量"><a href="#设置环境变量" class="headerlink" title="设置环境变量"></a>设置环境变量</h2><p>在自己的.bashrc的最后添加以下代码</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">export PATH=/usr/local/cuda-8.0/bin$&#123;PATH:+:$&#123;PATH&#125;&#125;</span><br><span class="line">export LD_LIBRARY_PATH=/usr/local/cuda-8.0/lib64$&#123;LD_LIBRARY_PATH:+:$&#123;LD_LIBRARY_PATH&#125;&#125;</span><br></pre></td></tr></table></figure>
<p>使用环境变量设置立即生效：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_">$ </span><span class="language-bash"><span class="built_in">source</span> ~/.bashrc</span></span><br></pre></td></tr></table></figure>

<h2 id="安装官方示例并验证环境"><a href="#安装官方示例并验证环境" class="headerlink" title="安装官方示例并验证环境"></a>安装官方示例并验证环境</h2><p>在些之前最后重启一下系统，以使驱动生效。<br>查看驱动等信息是否正常：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_">$ </span><span class="language-bash"><span class="built_in">cat</span> /proc/driver/nvidia/version</span></span><br></pre></td></tr></table></figure>
<p>我这里的输出如下：</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">NVRM version: NVIDIA UNIX x86_64 Kernel Module  367.57  Mon Oct  3 20:37:01 PDT 2016</span><br><span class="line">GCC version:  gcc version 5.4.0 20160609 (Ubuntu 5.4.0-6ubuntu1~16.04.4)</span><br></pre></td></tr></table></figure>

<p>如果上面的环境变量已经配置完成，则可以使用以下命令安装官方示例到用户根目录：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_">$ </span><span class="language-bash">cuda-install-samples-8.0.sh  ~</span></span><br></pre></td></tr></table></figure>

<p>进入刚安装的CUDA官方示例文件夹NVIDIA_CUDA-8.0_Samples运行make进行示例的编译。<br>如果没有问题的话，稍后会编译成功，编译完成之后会在目录<code>NVIDIA_CUDA-8.0_Samples/bin/x86_64/linux/release</code>中生成deviceQuery<br>运行查询输出</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_">$ </span><span class="language-bash">./deviceQuery</span></span><br></pre></td></tr></table></figure>
<p>我这里的输出结果如下：</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br></pre></td><td class="code"><pre><span class="line">./deviceQuery Starting...</span><br><span class="line"></span><br><span class="line"> CUDA Device Query (Runtime API) version (CUDART static linking)</span><br><span class="line"></span><br><span class="line">Detected 1 CUDA Capable device(s)</span><br><span class="line"></span><br><span class="line">Device 0: &quot;GeForce GTX 1080&quot;</span><br><span class="line">  CUDA Driver Version / Runtime Version          8.0 / 8.0</span><br><span class="line">  CUDA Capability Major/Minor version number:    6.1</span><br><span class="line">  Total amount of global memory:                 8112 MBytes (8506179584 bytes)</span><br><span class="line">  (20) Multiprocessors, (128) CUDA Cores/MP:     2560 CUDA Cores</span><br><span class="line">  GPU Max Clock rate:                            1734 MHz (1.73 GHz)</span><br><span class="line">  Memory Clock rate:                             5005 Mhz</span><br><span class="line">  Memory Bus Width:                              256-bit</span><br><span class="line">  L2 Cache Size:                                 2097152 bytes</span><br><span class="line">  Maximum Texture Dimension Size (x,y,z)         1D=(131072), 2D=(131072, 65536), 3D=(16384, 16384, 16384)</span><br><span class="line">  Maximum Layered 1D Texture Size, (num) layers  1D=(32768), 2048 layers</span><br><span class="line">  Maximum Layered 2D Texture Size, (num) layers  2D=(32768, 32768), 2048 layers</span><br><span class="line">  Total amount of constant memory:               65536 bytes</span><br><span class="line">  Total amount of shared memory per block:       49152 bytes</span><br><span class="line">  Total number of registers available per block: 65536</span><br><span class="line">  Warp size:                                     32</span><br><span class="line">  Maximum number of threads per multiprocessor:  2048</span><br><span class="line">  Maximum number of threads per block:           1024</span><br><span class="line">  Max dimension size of a thread block (x,y,z): (1024, 1024, 64)</span><br><span class="line">  Max dimension size of a grid size    (x,y,z): (2147483647, 65535, 65535)</span><br><span class="line">  Maximum memory pitch:                          2147483647 bytes</span><br><span class="line">  Texture alignment:                             512 bytes</span><br><span class="line">  Concurrent copy and kernel execution:          Yes with 2 copy engine(s)</span><br><span class="line">  Run time limit on kernels:                     No</span><br><span class="line">  Integrated GPU sharing Host Memory:            No</span><br><span class="line">  Support host page-locked memory mapping:       Yes</span><br><span class="line">  Alignment requirement for Surfaces:            Yes</span><br><span class="line">  Device has ECC support:                        Disabled</span><br><span class="line">  Device supports Unified Addressing (UVA):      Yes</span><br><span class="line">  Device PCI Domain ID / Bus ID / location ID:   0 / 3 / 0</span><br><span class="line">  Compute Mode:</span><br><span class="line">     &lt; Default (multiple host threads can use ::cudaSetDevice() with device simultaneously) &gt;</span><br><span class="line"></span><br><span class="line">deviceQuery, CUDA Driver = CUDART, CUDA Driver Version = 8.0, CUDA Runtime Version = 8.0, NumDevs = 1, Device0 = GeForce GTX 1080</span><br><span class="line">Result = PASS</span><br></pre></td></tr></table></figure>
<p>只要最后输出中显示结果为PASS即表示安装完成</p>
<h1 id="手动配置CUDA环境"><a href="#手动配置CUDA环境" class="headerlink" title="手动配置CUDA环境"></a>手动配置CUDA环境</h1><h2 id="安装显卡驱动并配置双显卡"><a href="#安装显卡驱动并配置双显卡" class="headerlink" title="安装显卡驱动并配置双显卡"></a>安装显卡驱动并配置双显卡</h2><p>对于桌面系统肯定希望安装nvidia显卡之后不会影响之前系统的正常使用，例如笔记本自带的intel显卡，和nvidia的显卡，此时可以通过bumblebee进行管理来切换双显卡。<br>可以通过ppa进行bumblebee安装。为了能够安装最新的nvidia显卡驱动，这里同样可以使用ppa来进行安装最新的显卡驱动。<br>首先删除系统中已经有的相关软件包：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">sudo apt-get purge nvidia* bumblebee* nouveau*</span><br></pre></td></tr></table></figure>

<h3 id="安装Nvidia显卡驱动"><a href="#安装Nvidia显卡驱动" class="headerlink" title="安装Nvidia显卡驱动"></a>安装Nvidia显卡驱动</h3><p>安装显卡ppa并更新缓存：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">sudo add-apt-repository ppa:graphics-drivers/ppa</span><br><span class="line">sudo apt-get update</span><br></pre></td></tr></table></figure>
<p>可以添加后只更新一次缓存。</p>
<p>然后自己去nvidia官方查询你自己的显卡对应的linux下最新版本驱动的版本号，然后按如下替换安装nvidia显卡驱动所需要的包（可以通过Tab键补全的方式来安装最新版本的驱动）：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">sudo apt install nvidia-375 nvidia-prime</span><br></pre></td></tr></table></figure>
<p>或者通过以下命令查看系统中所有可以安装的驱动：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">sudo ubuntu-drivers list</span><br></pre></td></tr></table></figure>

<p>然后运行以下命令生成nvidia的配置文件（有些系统可能并不需要）：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">sudo nvidia-xconfig </span><br></pre></td></tr></table></figure>

<p>重启系统，如果安装成功，此时使用的应该就是nvidia的显卡。可以运行<code>glxgears</code>来查看fps，如果提示没有该命令，就需要多安装一个包：<code>sudo apt-get install mesa-utils</code><br>也可以通过命令：<code>glxinfo | head</code>查看当前启用的是不是nvidia显卡<br>或者直接打开设置中的关于也可以查看当前使用的显卡<br>运行以下命令打开nvidia显卡配置程序：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">sudo nvidia-settings</span><br></pre></td></tr></table></figure>
<p>如果不考虑双显卡切换的问题，到这里就可以直接跳到CUDA安装部分了<br>如果执行上述命令有如下提示：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">** Message: PRIME: No offloading required. Abort</span><br><span class="line">** Message: PRIME: is it supported? no</span><br></pre></td></tr></table></figure>
<p>说明你的显卡不支持Nvidia的prime技术，或者说你显卡当前的驱动还不支持该技术，这样的话后面的双显卡切换就可以直接跳过了。</p>
<h3 id="配置双显卡驱动切换"><a href="#配置双显卡驱动切换" class="headerlink" title="配置双显卡驱动切换"></a>配置双显卡驱动切换</h3><p>安装bumblebee的ppa并更新缓存：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">sudo add-apt-repository ppa:bumblebee/stable</span><br><span class="line">sudo apt-get update</span><br></pre></td></tr></table></figure>

<p>执行以下命令安装bumblebee以及相关包：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">sudo apt-get install primus nvidia-profiler nvidia-visual-profiler nvidia-prime nvidia-prime-applet bumblebee-nvidia</span><br></pre></td></tr></table></figure>
<p>重启系统之后应该就可以看到状态栏里面有个显卡切换的图标了</p>
<p>如果上述命令在更新包缓存时出现404，并且安装<code>nvidia-prime-applet</code>时提示无法找到该包，则可以在<code>/etc/apt/source.list.d/</code>中删除刚添加的这个源，换成以下源并安装他的prime-indicator：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">sudo add-apt-repository ppa:nilarimogard/webupd8</span><br><span class="line">sudo apt-get update</span><br><span class="line">sudo apt-get install prime-indicator-plus</span><br></pre></td></tr></table></figure>

<p>如果<code>nvidia-settings</code>运行之后提示支持prime，也可以直接在这个里面的<code>PRIME Profiles</code>进行显卡的切换，而不需要再安装那个indicator</p>
<h2 id="安装cuda"><a href="#安装cuda" class="headerlink" title="安装cuda"></a>安装cuda</h2><p>安装cuda之前需要进行c++环境的安装，参见前面的内容<br>从官方下载cuda的二进制runfile文件，之所以使用这个文件安装也是为了避免安装的驱动破坏了之前已经配置好的驱动</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">wget https://developer.nvidia.com/compute/cuda/8.0/prod/local_installers/cuda_8.0.44_linux-run</span><br></pre></td></tr></table></figure>
<p>然后执行以下命令进行安装：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">sudo sh cuda_8.0.44_linux.run</span><br></pre></td></tr></table></figure>
<p>注意安装过程中不要安装显卡驱动，其他根据需要按提示操作即可。<br>安装完成之后记得配置环境变量，跟上面一样，增加如下内容到.bashrc的最后：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">export PATH=/usr/local/cuda-8.0/bin$&#123;PATH:+:$&#123;PATH&#125;&#125;</span><br><span class="line">export LD_LIBRARY_PATH=/usr/local/cuda-8.0/lib64$&#123;LD_LIBRARY_PATH:+:$&#123;LD_LIBRARY_PATH&#125;&#125;</span><br></pre></td></tr></table></figure>
<p>然后：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">source ~/.bashrc</span><br></pre></td></tr></table></figure>
<p>不过runfile的官方安装结束之后会提示增加libs到ld.so.conf中。可以添加如下文件：<br><code>/etc/ld.so.conf.d/cuda.conf</code>，内容为<code>/usr/local/cuda-8.0/lib64</code>，然后运行：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">sudo ldconfig</span><br></pre></td></tr></table></figure>
<p>至此CUDA的显卡都已经安装完成，通过显卡切换程序将显卡切换为Nvidia显卡之后，即可像上面的验证过程一样，验证CUDA是否正常运行</p>
<h1 id="常见问题"><a href="#常见问题" class="headerlink" title="常见问题"></a>常见问题</h1><h2 id="sbin-ldconfig-real-usr-lib-nvidia-384-libEGL-so-1-is-not-a-symbolic-link"><a href="#sbin-ldconfig-real-usr-lib-nvidia-384-libEGL-so-1-is-not-a-symbolic-link" class="headerlink" title="/sbin/ldconfig.real: /usr/lib/nvidia-384/libEGL.so.1 is not a symbolic link"></a>/sbin/ldconfig.real: /usr/lib/nvidia-384/libEGL.so.1 is not a symbolic link</h2><p>解决方法是手动创建一个符号链接，或者使用root权限执行以下命令来进行：<br>然后再次手动运行<code>sudo ldconfig</code>，发现已经没有那个错误提示了</p>
<figure class="highlight sh"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#! /bin/sh</span></span><br><span class="line"><span class="comment">#</span></span><br><span class="line"><span class="comment"># find the file in /usr/lib</span></span><br><span class="line">LIBEGL=`find /usr/lib/nvidia* -name libEGL.so.\* | egrep <span class="string">&quot;[0-9][0-9]*\.[0-9][0-9]*$&quot;</span>`</span><br><span class="line">LIBEGL_LINK=`<span class="built_in">echo</span> <span class="variable">$LIBEGL</span> | sed <span class="string">&#x27;s/[0-9][0-9]*\.[0-9][0-9]*$/1/&#x27;</span>`</span><br><span class="line"><span class="built_in">printf</span> <span class="string">&quot;\n\nThe following commands will be executed:\n+++++++++++++++++++++++++++++++++++++++\n&quot;</span></span><br><span class="line"><span class="built_in">printf</span> <span class="string">&quot;mv <span class="variable">$LIBEGL_LINK</span> <span class="variable">$&#123;LIBEGL_LINK&#125;</span>.orig\nln -s <span class="variable">$LIBEGL</span> <span class="variable">$LIBEGL_LINK</span>\n\n&quot;</span></span><br><span class="line"><span class="keyword">while</span> <span class="literal">true</span>; <span class="keyword">do</span></span><br><span class="line">    <span class="built_in">read</span> -p <span class="string">&quot;Do you wish to perform these commands?  &quot;</span> yn</span><br><span class="line">    <span class="keyword">case</span> <span class="variable">$yn</span> <span class="keyword">in</span></span><br><span class="line">        [Yy]* ) <span class="built_in">mv</span> <span class="variable">$LIBEGL_LINK</span> <span class="variable">$&#123;LIBEGL_LINK&#125;</span>.orig; <span class="built_in">ln</span> -s <span class="variable">$LIBEGL</span> <span class="variable">$LIBEGL_LINK</span> ; <span class="built_in">break</span>;;</span><br><span class="line">        [Nn]* ) <span class="built_in">break</span>;;</span><br><span class="line">        * ) <span class="built_in">echo</span> <span class="string">&quot;Please answer yes or no.&quot;</span>;;</span><br><span class="line">    <span class="keyword">esac</span></span><br><span class="line"><span class="keyword">done</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># find the file in /usr/lib32</span></span><br><span class="line">LIBEGL=`find /usr/lib32/nvidia* -name libEGL.so.\* | egrep <span class="string">&quot;[0-9][0-9]*\.[0-9][0-9]*$&quot;</span>`</span><br><span class="line">LIBEGL_LINK=`<span class="built_in">echo</span> <span class="variable">$LIBEGL</span> | sed <span class="string">&#x27;s/[0-9][0-9]*\.[0-9][0-9]*$/1/&#x27;</span>`</span><br><span class="line"><span class="built_in">printf</span> <span class="string">&quot;\n\nThe following commands will be executed:\n+++++++++++++++++++++++++++++++++++++++\n&quot;</span></span><br><span class="line"><span class="built_in">printf</span> <span class="string">&quot;mv <span class="variable">$LIBEGL_LINK</span> <span class="variable">$&#123;LIBEGL_LINK&#125;</span>.orig\nln -s <span class="variable">$LIBEGL</span> <span class="variable">$LIBEGL_LINK</span>\n\n&quot;</span></span><br><span class="line"><span class="keyword">while</span> <span class="literal">true</span>; <span class="keyword">do</span></span><br><span class="line">    <span class="built_in">read</span> -p <span class="string">&quot;Do you wish to perform these commands?  &quot;</span> yn</span><br><span class="line">    <span class="keyword">case</span> <span class="variable">$yn</span> <span class="keyword">in</span></span><br><span class="line">        [Yy]* ) <span class="built_in">mv</span> <span class="variable">$LIBEGL_LINK</span> <span class="variable">$&#123;LIBEGL_LINK&#125;</span>.orig; <span class="built_in">ln</span> -s <span class="variable">$LIBEGL</span> <span class="variable">$LIBEGL_LINK</span> ; <span class="built_in">break</span>;;</span><br><span class="line">        [Nn]* ) <span class="built_in">break</span>;;</span><br><span class="line">        * ) <span class="built_in">echo</span> <span class="string">&quot;Please answer yes or no.&quot;</span>;;</span><br><span class="line">    <span class="keyword">esac</span></span><br><span class="line"><span class="keyword">done</span></span><br></pre></td></tr></table></figure>


    </div>

    
    
    
        

  <div class="followme">
    <p>Welcome to my other publishing channels</p>

    <div class="social-list">

        <div class="social-item">
          <a target="_blank" class="social-link" href="/atom.xml">
            <span class="icon">
              <i class="fa fa-rss"></i>
            </span>

            <span class="label">RSS</span>
          </a>
        </div>
    </div>
  </div>


      <footer class="post-footer">
          <div class="post-tags">
              <a href="/tags/CUDA/" rel="tag"># CUDA</a>
              <a href="/tags/Linux/" rel="tag"># Linux</a>
              <a href="/tags/Ubuntu/" rel="tag"># Ubuntu</a>
          </div>

        


        
    <div class="post-nav">
      <div class="post-nav-item">
    <a href="/2017/01/19/linux-command-tools-ufw/" rel="prev" title="Linux实用工具总结之UFW">
      <i class="fa fa-chevron-left"></i> Linux实用工具总结之UFW
    </a></div>
      <div class="post-nav-item">
    <a href="/2017/03/01/ubuntu-compile-opencv2-with-cuda-and-ffmpeg/" rel="next" title="Ubuntu 16.04下编译OpenCV 2.4.13支持FFmpeg以及CUDA 8加速图像处理">
      Ubuntu 16.04下编译OpenCV 2.4.13支持FFmpeg以及CUDA 8加速图像处理 <i class="fa fa-chevron-right"></i>
    </a></div>
    </div>
      </footer>
    
  </article>
  
  
  



          </div>
          
    <div class="comments" id="gitalk-container"></div>

<script>
  window.addEventListener('tabs:register', () => {
    let { activeClass } = CONFIG.comments;
    if (CONFIG.comments.storage) {
      activeClass = localStorage.getItem('comments_active') || activeClass;
    }
    if (activeClass) {
      let activeTab = document.querySelector(`a[href="#comment-${activeClass}"]`);
      if (activeTab) {
        activeTab.click();
      }
    }
  });
  if (CONFIG.comments.storage) {
    window.addEventListener('tabs:click', event => {
      if (!event.target.matches('.tabs-comment .tab-content .tab-pane')) return;
      let commentClass = event.target.classList[1];
      localStorage.setItem('comments_active', commentClass);
    });
  }
</script>

        </div>
          
  
  <div class="toggle sidebar-toggle">
    <span class="toggle-line toggle-line-first"></span>
    <span class="toggle-line toggle-line-middle"></span>
    <span class="toggle-line toggle-line-last"></span>
  </div>

  <aside class="sidebar">
    <div class="sidebar-inner">

      <ul class="sidebar-nav motion-element">
        <li class="sidebar-nav-toc">
          Table of Contents
        </li>
        <li class="sidebar-nav-overview">
          Overview
        </li>
      </ul>

      <!--noindex-->
      <div class="post-toc-wrap sidebar-panel">
          <div class="post-toc motion-element"><ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#%E6%A0%B9%E6%8D%AEnvidia%E5%AE%98%E6%96%B9%E6%89%8B%E5%86%8C%E5%AE%89%E8%A3%85"><span class="nav-number">1.</span> <span class="nav-text">根据nvidia官方手册安装</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#%E5%AE%89%E8%A3%85%E5%87%86%E5%A4%87"><span class="nav-number">1.1.</span> <span class="nav-text">安装准备</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#%E9%AA%8C%E8%AF%81NVIDIA%E6%98%BE%E5%8D%A1"><span class="nav-number">1.1.1.</span> <span class="nav-text">验证NVIDIA显卡</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E6%9F%A5%E7%9C%8Blinux%E7%B3%BB%E7%BB%9F%E4%BF%A1%E6%81%AF"><span class="nav-number">1.1.2.</span> <span class="nav-text">查看linux系统信息</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E5%AE%89%E8%A3%85gcc%E5%8F%8Ag"><span class="nav-number">1.1.3.</span> <span class="nav-text">安装gcc及g++</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E5%AE%89%E8%A3%85linux-kernel-header%E5%8F%8A%E5%BC%80%E5%8F%91%E5%8C%85"><span class="nav-number">1.1.4.</span> <span class="nav-text">安装linux kernel header及开发包</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E4%B8%8B%E8%BD%BD%E5%B9%B6%E5%AE%89%E8%A3%85CUDA"><span class="nav-number">1.2.</span> <span class="nav-text">下载并安装CUDA</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E8%AE%BE%E7%BD%AE%E7%8E%AF%E5%A2%83%E5%8F%98%E9%87%8F"><span class="nav-number">1.3.</span> <span class="nav-text">设置环境变量</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E5%AE%89%E8%A3%85%E5%AE%98%E6%96%B9%E7%A4%BA%E4%BE%8B%E5%B9%B6%E9%AA%8C%E8%AF%81%E7%8E%AF%E5%A2%83"><span class="nav-number">1.4.</span> <span class="nav-text">安装官方示例并验证环境</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#%E6%89%8B%E5%8A%A8%E9%85%8D%E7%BD%AECUDA%E7%8E%AF%E5%A2%83"><span class="nav-number">2.</span> <span class="nav-text">手动配置CUDA环境</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#%E5%AE%89%E8%A3%85%E6%98%BE%E5%8D%A1%E9%A9%B1%E5%8A%A8%E5%B9%B6%E9%85%8D%E7%BD%AE%E5%8F%8C%E6%98%BE%E5%8D%A1"><span class="nav-number">2.1.</span> <span class="nav-text">安装显卡驱动并配置双显卡</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#%E5%AE%89%E8%A3%85Nvidia%E6%98%BE%E5%8D%A1%E9%A9%B1%E5%8A%A8"><span class="nav-number">2.1.1.</span> <span class="nav-text">安装Nvidia显卡驱动</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E9%85%8D%E7%BD%AE%E5%8F%8C%E6%98%BE%E5%8D%A1%E9%A9%B1%E5%8A%A8%E5%88%87%E6%8D%A2"><span class="nav-number">2.1.2.</span> <span class="nav-text">配置双显卡驱动切换</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E5%AE%89%E8%A3%85cuda"><span class="nav-number">2.2.</span> <span class="nav-text">安装cuda</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#%E5%B8%B8%E8%A7%81%E9%97%AE%E9%A2%98"><span class="nav-number">3.</span> <span class="nav-text">常见问题</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#sbin-ldconfig-real-usr-lib-nvidia-384-libEGL-so-1-is-not-a-symbolic-link"><span class="nav-number">3.1.</span> <span class="nav-text">&#x2F;sbin&#x2F;ldconfig.real: &#x2F;usr&#x2F;lib&#x2F;nvidia-384&#x2F;libEGL.so.1 is not a symbolic link</span></a></li></ol></li></ol></div>
      </div>
      <!--/noindex-->

      <div class="site-overview-wrap sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
    <img class="site-author-image" itemprop="image" alt="blueyi"
      src="/images/default_avatar.jpg">
  <p class="site-author-name" itemprop="name">blueyi</p>
  <div class="site-description" itemprop="description">心怀善意，虛怀若谷！</div>
</div>
<div class="site-state-wrap motion-element">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
          <a href="/archives/">
        
          <span class="site-state-item-count">104</span>
          <span class="site-state-item-name">posts</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
            <a href="/categories/">
          
        <span class="site-state-item-count">26</span>
        <span class="site-state-item-name">categories</span></a>
      </div>
      <div class="site-state-item site-state-tags">
            <a href="/tags/">
          
        <span class="site-state-item-count">68</span>
        <span class="site-state-item-name">tags</span></a>
      </div>
  </nav>
</div>
  <div class="links-of-author motion-element">
      <span class="links-of-author-item">
        <a href="https://github.com/blueyi" title="GitHub → https:&#x2F;&#x2F;github.com&#x2F;blueyi" rel="noopener" target="_blank"><i class="fab fa-github fa-fw"></i>GitHub</a>
      </span>
  </div>


  <div class="links-of-blogroll motion-element">
    <div class="links-of-blogroll-title"><i class="fa fa-link fa-fw"></i>
      Links
    </div>
    <ul class="links-of-blogroll-list">
        <li class="links-of-blogroll-item">
          <a href="http://maxwi.com/" title="http:&#x2F;&#x2F;maxwi.com" rel="noopener" target="_blank">Maxwi</a>
        </li>
    </ul>
  </div>

      </div>

    </div>
  </aside>
  <div id="sidebar-dimmer"></div>


      </div>
    </main>

    <footer class="footer">
      <div class="footer-inner">
        

        

<div class="copyright">
  
  &copy; 2014 – 
  <span itemprop="copyrightYear">2022</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">blueyi</span>
    <span class="post-meta-divider">|</span>
    <span class="post-meta-item-icon">
      <i class="fa fa-chart-area"></i>
    </span>
    <span title="Symbols count total">750k</span>
    <span class="post-meta-divider">|</span>
    <span class="post-meta-item-icon">
      <i class="fa fa-coffee"></i>
    </span>
    <span title="Reading time total">11:22</span>
</div>
  <div class="powered-by">Powered by <a href="https://hexo.io/" class="theme-link" rel="noopener" target="_blank">Hexo</a> & <a href="https://mist.theme-next.org/" class="theme-link" rel="noopener" target="_blank">NexT.Mist</a>
  </div>

        








      </div>
    </footer>
  </div>

  
  <script src="/lib/anime.min.js"></script>
  <script src="/lib/pjax/pjax.min.js"></script>
  <script src="//cdn.jsdelivr.net/npm/jquery@3/dist/jquery.min.js"></script>
  <script src="//cdn.jsdelivr.net/gh/fancyapps/fancybox@3/dist/jquery.fancybox.min.js"></script>
  <script src="//cdn.jsdelivr.net/npm/lozad@1/dist/lozad.min.js"></script>

<script src="/js/utils.js"></script>


<script src="/js/schemes/muse.js"></script>


<script src="/js/next-boot.js"></script>

<script src="/js/bookmark.js"></script>

  <script>
var pjax = new Pjax({
  selectors: [
    'head title',
    '#page-configurations',
    '.content-wrap',
    '.post-toc-wrap',
    '.languages',
    '#pjax'
  ],
  switches: {
    '.post-toc-wrap': Pjax.switches.innerHTML
  },
  analytics: false,
  cacheBust: false,
  scrollTo : !CONFIG.bookmark.enable
});

window.addEventListener('pjax:success', () => {
  document.querySelectorAll('script[data-pjax], script#page-configurations, #pjax script').forEach(element => {
    var code = element.text || element.textContent || element.innerHTML || '';
    var parent = element.parentNode;
    parent.removeChild(element);
    var script = document.createElement('script');
    if (element.id) {
      script.id = element.id;
    }
    if (element.className) {
      script.className = element.className;
    }
    if (element.type) {
      script.type = element.type;
    }
    if (element.src) {
      script.src = element.src;
      // Force synchronous loading of peripheral JS.
      script.async = false;
    }
    if (element.dataset.pjax !== undefined) {
      script.dataset.pjax = '';
    }
    if (code !== '') {
      script.appendChild(document.createTextNode(code));
    }
    parent.appendChild(script);
  });
  NexT.boot.refresh();
  // Define Motion Sequence & Bootstrap Motion.
  if (CONFIG.motion.enable) {
    NexT.motion.integrator
      .init()
      .add(NexT.motion.middleWares.subMenu)
      .add(NexT.motion.middleWares.postList)
      .bootstrap();
  }
  NexT.utils.updateSidebarPosition();
});
</script>




  
  <script data-pjax>
    (function(){
      var canonicalURL, curProtocol;
      //Get the <link> tag
      var x=document.getElementsByTagName("link");
		//Find the last canonical URL
		if(x.length > 0){
			for (i=0;i<x.length;i++){
				if(x[i].rel.toLowerCase() == 'canonical' && x[i].href){
					canonicalURL=x[i].href;
				}
			}
		}
    //Get protocol
	    if (!canonicalURL){
	    	curProtocol = window.location.protocol.split(':')[0];
	    }
	    else{
	    	curProtocol = canonicalURL.split(':')[0];
	    }
      //Get current URL if the canonical URL does not exist
	    if (!canonicalURL) canonicalURL = window.location.href;
	    //Assign script content. Replace current URL with the canonical URL
      !function(){var e=/([http|https]:\/\/[a-zA-Z0-9\_\.]+\.baidu\.com)/gi,r=canonicalURL,t=document.referrer;if(!e.test(r)){var n=(String(curProtocol).toLowerCase() === 'https')?"https://sp0.baidu.com/9_Q4simg2RQJ8t7jm9iCKT-xh_/s.gif":"//api.share.baidu.com/s.gif";t?(n+="?r="+encodeURIComponent(document.referrer),r&&(n+="&l="+r)):r&&(n+="?l="+r);var i=new Image;i.src=n}}(window);})();
  </script>




  
<script src="/js/local-search.js"></script>













    <div id="pjax">
  

  

<link rel="stylesheet" href="//cdn.jsdelivr.net/npm/gitalk@1/dist/gitalk.min.css">

<script>
NexT.utils.loadComments(document.querySelector('#gitalk-container'), () => {
  NexT.utils.getScript('//cdn.jsdelivr.net/npm/gitalk@1/dist/gitalk.min.js', () => {
    var gitalk = new Gitalk({
      clientID    : '0f8243eb2c8b2207980f',
      clientSecret: 'd159633a33519d3b7a48b0ca729032f7d1f38a41',
      repo        : 'notes',
      owner       : 'blueyi',
      admin       : ['blueyi'],
      id          : '63073264ab20625565a78e2a6805d655',
        language: '',
      distractionFreeMode: true
    });
    gitalk.render('gitalk-container');
  }, window.Gitalk);
});
</script>

    </div>
</body>
</html>
